package com.nlp.visualization.crawler.pipeline;

import com.nlp.visualization.pojo.crawler.NewsJson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

/**
 * @author LXM
 * @Title: BufferPipeline
 * @Description: 格式化新闻的主要内容，存进缓冲区中
 * @date 2018/3/4上午11:39
 */
public class BufferPipeline implements Pipeline {

    private Logger logger = LoggerFactory.getLogger(BufferPipeline.class);


    @Override
    public void process(ResultItems resultItems, Task task) {

        //实例一个新闻类
        NewsJson.ItemsBean itemsBean = new NewsJson.ItemsBean();
        itemsBean.setContent(resultItems.get("article").toString());
        itemsBean.setDatetime(resultItems.get("date").toString());
        itemsBean.setTitle(resultItems.get("main_title"));
        itemsBean.setUrl(resultItems.get("url").toString());
        //获取一个缓冲区的单例，保存这条item
        JsonBuffer.getInstance().addObjectToList(itemsBean);

    }
}
